package com.wnnight.wys.mapper.car;


import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.wnnight.wys.entity.car.Car;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * @ClassName: CarMapper
 * @Description: 车辆mapper
 * @author: CHX42
 * @date: 2022/8/27-17:30
 * @version: v1.0
 */

public interface CarMapper extends BaseMapper<Car> {
    @Select("select * from wys_car")
    List<Car> selectAll();

    @Select("SELECT * FROM wys_car left JOIN wys_landlord ON wys_car.landlord_id=wys_landlord.id ${ew.customSqlSegment} ORDER BY wys_car.car_num")
    Page<Car> getPage(IPage<Car> carPage, @Param("ew") Wrapper wrapper);

    @Select("SELECT id FROM wys_landlord WHERE phone=#{phone}")
    Integer getLandlordByPhone(String phone);

    @Select("select * from ${prefix}car where landlord_id=#{landlordId}")
    @Results({
            @Result(column = "id",property = "id",id = true),
            @Result(column = "car_num",property = "carNum"),
            @Result(column = "reg_time",property = "regTime"),
            @Result(column = "end_time",property = "endTime")
    })
    List<Car> getByLandlordId(int landlordId);
}
